//@Author: wulinlin
//@Description:
//@File:  enterprise_repo
//@Version: 1.0.0
//@Date: 2024/04/17 22:40

package repo

import (
	"context"
	"ebip/internel/domain"
	"ebip/internel/repository/dao"
	"ebip/internel/repository/dao/enterprise_dao"
	"github.com/ecodeclub/ekit/slice"
	"gorm.io/gorm"
)

type EnterpriseRepo interface {
	//
	// AddEnterpriseBaseInfo
	//  @Description: 新增/批量新增 企业信息
	//
	AddEnterpriseBaseInfo(ctx context.Context, bizId int64, biz string, data domain.EnterpriseBasicDM) error
	BatchAddEnterpriseBaseInfo(ctx context.Context, bizId int64, biz string, data []domain.EnterpriseBasicDM) error
}

func NewEnterpriseRepo(dao enterprise_dao.EnterpriseDAO) EnterpriseRepo {
	return &enterpriseRepo{
		dao: dao,
	}
}

type enterpriseRepo struct {
	dao enterprise_dao.EnterpriseDAO
}

func (e *enterpriseRepo) AddEnterpriseBaseInfo(ctx context.Context, bizId int64, biz string, data domain.EnterpriseBasicDM) error {
	return e.dao.InsertEnterpriseBaseInfo(ctx, e.toEntity(data))
}

func (e *enterpriseRepo) BatchAddEnterpriseBaseInfo(ctx context.Context, bizId int64, biz string, data []domain.EnterpriseBasicDM) error {
	i := slice.Map[domain.EnterpriseBasicDM, dao.EnterpriseBasicModel](data, func(idx int, src domain.EnterpriseBasicDM) dao.EnterpriseBasicModel {
		return e.toEntity(src)
	})
	return e.dao.BatchInsertEnterpriseBaseInfo(ctx, i)
}

func (e *enterpriseRepo) toEntity(item domain.EnterpriseBasicDM) dao.EnterpriseBasicModel {
	return dao.EnterpriseBasicModel{
		Model: gorm.Model{
			ID:        uint(item.Id),
			CreatedAt: item.CreatedAt,
			UpdatedAt: item.UpdatedAt,
		},
		CompanyName:                item.CompanyName,
		RegStatus:                  item.RegStatus,
		LegalBoss:                  item.LegalBoss,
		RegCapital:                 item.RegCapital,
		RegDate:                    item.RegDate,
		SocialCode:                 item.SocialCode,
		CompanyRegAddr:             item.CompanyRegAddr,
		Phone:                      item.Phone,
		Email:                      item.Email,
		Province:                   item.Province,
		City:                       item.City,
		District:                   item.District,
		TaxNumber:                  item.TaxNumber,
		RegNumber:                  item.RegNumber,
		OrgCode:                    item.OrgCode,
		InsuredNumber:              item.InsuredNumber,
		InsuredNumberReport:        item.InsuredNumberReport,
		CompanyType:                item.CompanyType,
		CompanySize:                item.CompanySize,
		ApprovalDate:               item.ApprovalDate,
		BusinessTerm:               item.BusinessTerm,
		GBIndustryCategory:         item.GBIndustryCategory,
		GBIndustryMajorCategory:    item.GBIndustryMajorCategory,
		GBIndustryMediumCategory:   item.GBIndustryMediumCategory,
		GBIndustrySmallCategory:    item.GBIndustrySmallCategory,
		FormerName:                 item.FormerName,
		EnglishName:                item.EnglishName,
		OfficialWebsite:            item.OfficialWebsite,
		CommunicationAdd:           item.CommunicationAdd,
		CompanyProfile:             item.CompanyProfile,
		BusinessScope:              item.BusinessScope,
		EBIPIndustryCategory:       item.EBIPIndustryCategory,
		EBIPIndustryMajorCategory:  item.EBIPIndustryMajorCategory,
		EBIPIndustryMediumCategory: item.EBIPIndustryMediumCategory,
		EBIPIndustrySmallCategory:  item.EBIPIndustrySmallCategory,
	}
}
